package com.itxiao.controller;

import com.itxiao.pojo.dto.LoginBo;
import com.itxiao.pojo.dto.SendCodeDTO;
import com.itxiao.service.LoginService;
import com.itxiao.pojo.bo.SysUserLoginBo;
import com.itxiao.pojo.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.io.IOException;

/**
 * @Author xjy
 * @Date 2025/9/18 17:31
 */
@RestController
@RequestMapping("admin/api/v1/login")
@Api(tags = "登录模块")
@CrossOrigin
public class LoginController {
    /**
     * 服务对象
     */
    @Resource
    private LoginService loginService;

    @ApiOperation("登录")
    @PostMapping("/login")
    public R login(@RequestBody SysUserLoginBo bo) {
        return loginService.login(bo);
    }
    @ApiOperation("发送验证码")
    @GetMapping("/verify")
    public R getVerify() throws IOException {
        return loginService.getVerify();
    }
    @ApiOperation("退出登录")
    @PostMapping("/login-out")
    public R logout() {
        return R.ok();
    }
    @ApiOperation("用户发送验证码")
    @PostMapping("/send-code")
    public R sendCode(@RequestBody @Valid SendCodeDTO dto)  {
        return loginService.sendCode(dto.getPhone());
    }
    @ApiOperation("用户登录")
    @PostMapping("/user-login")
    public R userLogin(@RequestBody LoginBo bo) {
        return loginService.userLogin(bo);
    }
}
